<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>煤炭管理系统</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/css/layui-theme-custom.css">
    <link rel="stylesheet" href="/static/css/member.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <#include "/base/main-header.ftl">

    <#include "/base/main-left.ftl">
    <div class="layui-body">
        <!-- 内容主体区域  -->
        <div class="site-title">
            <fieldset>
                <legend>
                    <a class="site-title-text">发布公告</a>
                </legend>
            </fieldset>
        </div>
        <form class="layui-form"  >
            <div class="table-box">
                <div class="layui-form-item">
                    <input type="hidden" name="id" value="${annoc.id!""}">
                    <label class="layui-form-label label-width">标题：</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="${annoc.title!""}"
                               lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item  ">
                    <label class="layui-form-label label-width" style="float: none">公告内容：</label>
                    <div class="layui-input-block">
                        <div id="content"  >
                            <p>
                                ${annoc.content!""}
                            </p>
                        </div>
                    </div>
                </div>
                <br><br>

                <label class="layui-form-label label-width"></label>
                <button type="submit" class="layui-btn layui-btn-radius" lay-submit lay-filter="publicAnnoc">发布公告</button>
                <button type="reset" class="layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="dartAnnoc">保存草稿</button>
            </div>
            <br><br>
        </form>

    </div>
    <#include "/base/main-footer.ftl">
</div>

<script src="/static/lib/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/wangEditor.min.js"></script>

<script>
    let E = window.wangEditor
    let editor = new E('#content')
    editor.create()
    layui.use(['layer', 'form', 'element', 'jquery','table'], function () {
        let layer = layui.layer, form = layui.form, $ = layui.jquery;
        let loading = false
        form.on('submit(dartAnnoc)', function (data) {
            if (loading){
                return false
            }
            loading = true
            const res = Object.assign(data.field,{annocStatus:0,content:editor.txt.html()})
            $.ajax({
                type: "POST",
                url: "/annoc/saveOrUpdate",
                data: JSON.stringify(res) ,
                dataType: "json",
                contentType: 'application/json; charset=UTF-8',
                success: function (data) {
                    if (data.isSuccess){
                        layer.msg("创建成功")
                        setTimeout(function () {
                            loading = false
                            window.location = "/announc"
                        },2000)
                    } else {
                        loading = false
                        layer.msg(data.msg)
                    }
                }
            });
            return false;
        });
        form.on('submit(publicAnnoc)', function (data) {
            if (loading){
                return false
            }
            loading = true
            const res = Object.assign(data.field,{annocStatus:1,content:editor.txt.html()})
            $.ajax({
                type: "POST",
                url: "/annoc/saveOrUpdate",
                data: JSON.stringify(res) ,
                dataType: "json",
                contentType: 'application/json; charset=UTF-8',
                success: function (data) {
                    if (data.isSuccess){
                        layer.msg("创建成功")
                        setTimeout(function () {
                            loading = false
                            window.location = "/announc"
                        },2000)
                    } else {
                        loading = false
                        layer.msg(data.msg)
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>